home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3552 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.1 KB  |  49 lines

  1. Newsgroups: comp.lang.c++
  2. Path: lynx.cs.washington.edu!xyu
  3. From: Xuri Yu <xyu@lynx.cs.washington.edu>
  4. Subject: data structure of quadtree
  5. Content-Type: TEXT/PLAIN; charset=US-ASCII
  6. Sender: news@beaver.cs.washington.edu (USENET News System)
  7. Organization: Computer Science & Engineering, U of Washington, Seattle
  8. Message-ID: <Pine.ULT.3.91.960124115310.21999A-100000@lynx.cs.washington.edu>
  9. Mime-Version: 1.0
  10. X-Nntp-Posting-Host: lynx.cs.washington.edu
  11. Date: Wed, 24 Jan 1996 20:02:48 GMT
  12.  
  13. Hello,
  14.  
  15.   I try to define the data structure of quadtree as follows:
  16.  
  17. class quadnode {
  18. protected:  
  19.  
  20. struct subnode {
  21.   float avgdata;
  22.   quadnode *child[2];
  23.   
  24.   subnode() { for (int i=0; i<2; i++) child[i] = new quadnode[2]; } 
  25. };
  26.  
  27.   union {
  28.     float data;
  29.     subnode *nextquad;
  30.   };
  31.  
  32. public:
  33.   quadnode(subnode *quad = NULL): nextquad(quad) {}
  34.   quadnode(float x): data(x) {}
  35.        
  36.   friend class quadtree;
  37. };
  38.  
  39. class quadtree {
  40. protected:
  41.   quadnode root;
  42.  ...
  43. };
  44.  
  45. The purpose of using 'union' is to save memory. The design doesn't work 
  46. well. Could anyone solve this problem? Thanks a lot.
  47.  
  48. Zuri
  49.